<?php
class AuctionsController extends AppController {

	var $name = 'Auctions';
	var $helpers = array('Javascript', 'Form', 'Html');
	var $components = array('Auth');

	function index() {
		$this->Auction->recursive = 0;
		$this->set('auctions', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid auction', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('auction', $this->Auction->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Auction->create();
			if ($this->Auction->save($this->data)) {
				$this->Session->setFlash(__('The auction has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The auction could not be saved. Please, try again.', true));
			}
		}
		$presses = $this->Auction->Press->find('list');
		$users = $this->Auction->User->find('list');
		$this->set(compact('presses', 'users'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid auction', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Auction->save($this->data)) {
				$this->Session->setFlash(__('The auction has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The auction could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Auction->read(null, $id);
		}
		$presses = $this->Auction->Press->find('list');
		$users = $this->Auction->User->find('list');
		$this->set(compact('presses', 'users'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for auction', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Auction->delete($id)) {
			$this->Session->setFlash(__('Auction deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Auction was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	function admin_index() {
		$this->Auction->recursive = 0;
		$this->set('auctions', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid auction', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('auction', $this->Auction->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Auction->create();
			if ($this->Auction->save($this->data)) {
				$this->Session->setFlash(__('The auction has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The auction could not be saved. Please, try again.', true));
			}
		}
		$presses = $this->Auction->Press->find('list');
		$users = $this->Auction->User->find('list');
		$this->set(compact('presses', 'users'));
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid auction', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Auction->save($this->data)) {
				$this->Session->setFlash(__('The auction has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The auction could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Auction->read(null, $id);
		}
		$presses = $this->Auction->Press->find('list');
		$users = $this->Auction->User->find('list');
		$this->set(compact('presses', 'users'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for auction', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Auction->delete($id)) {
			$this->Session->setFlash(__('Auction deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Auction was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>